<template>
  <div class="login-code">
    <el-form :model="form" label-width="80px" ref="phoneRulesRef" :rules="phoneRules" status-icon>
      <el-form-item label="手机号:" prop="phone">
        <el-input v-model="form.phone" clearable maxlength="11" />
      </el-form-item>
      <el-form-item label="验证码:" prop="code">
        <el-input v-model="form.code" clearable maxlength="6" />
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts" setup>
import { ref, reactive } from 'vue';
import type { FormInstance, FormRules } from 'element-plus';

const form = reactive({
  phone: '',
  code: '',
});

const phoneRulesRef = ref<FormInstance>();
const phoneRules: FormRules = {
  phone: [{ required: true, message: '请输入手机号码', trigger: 'blur' }],
  code: [{ required: true, message: '请输入验证码', trigger: 'blur' }],
};

const codeAction = () => {
  phoneRulesRef.value?.validate((isValida) => {
    if (!isValida) return;
  });
};

defineExpose({
  codeAction,
});
</script>

<style lang="scss" scoped></style>
